package com.boang.dao;

import com.boang.exception.MyException;
import com.boang.po.User;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

@Repository
public class UserDao {
    public static HashMap<Integer, User> userMap = new HashMap<Integer, User>();
    private static int userId = 1;

    public User selectById(Integer id) {
        if (userMap.containsKey(id)) {
            return userMap.get(id);
        }else {
            throw new MyException("未查到此用户");
        }
    }

    public void insert(User user) {
        user.setId(userId++);
        userMap.put(user.getId(), user);
    }

    public List<User> list() {
        return userMap.values().stream().toList();
    }
}
